package io.adrainty.algorithm.mars;

/**
 * 观光景点组合问题
 * @link <a href="https://www.marscode.cn/practice/364l85wv6oo6lq?problem_id=7424436653624328236">...</a>
 * @author adrainty
 * @version v1.0.0
 * @since 2024/11/22 下午1:02
 */

@SuppressWarnings("unused")
public class Solution011 {

    private Solution011() {}

    public static int solution(int[] values) {
        if (values == null || values.length < 2) {
            throw new IllegalArgumentException("Array length must be at least 2.");
        }

        int maxScore = Integer.MIN_VALUE;
        int maxI = values[0]; // 初始化最大值为第一个元素的值

        for (int j = 1; j < values.length; j++) {
            // 计算当前组合得分
            int currentScore = maxI + values[j] - j;
            maxScore = Math.max(maxScore, currentScore);

            // 更新 maxI，确保 maxI 是当前最大的 values[i] + i
            maxI = Math.max(maxI, values[j] + j);
        }

        return maxScore;
    }

    public static int solution1(int[] values) {
        // write code here
        int ans = Integer.MIN_VALUE;
        for (int i = 0; i < values.length; i++) {
            for (int j = i + 1; j < values.length; j++) {
                int sum = calc(values, i, j);
                ans = Math.max(ans, sum);
            }
        }
        return ans == Integer.MIN_VALUE? 0: ans; // Placeholder return
    }

    private static int calc(int[] values, int start, int end) {
        return values[start] + values[end] + start - end;
    }

}
